﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace P_SetUp
{
    /// <summary>
    /// PaymentRules
    /// </summary>
    public class Class_PaymentRules
    {
        private Mydb MyDb = new Mydb();

        #region 变量
        /// <summary>
        /// 地区名
        /// </summary>
        public string ZoneName;
        /// <summary>
        /// 服务类型
        /// </summary>
        public string ServType;
        #endregion
        
        #region 私有方法
        private void _AddInfo(string ChargeRule, string PayRule, int ChargeDiffMonths, int PayDiffMonths
, int StateDiffMonths, int InJobAddRepayMonths, int DelayCompensationMonths, bool IsLocalMonthStopPay
, bool IsNextMonthStopPay, int MaxStateMonths, int StateEndDay)
        {
            string Sql = string.Format(@"Insert Into Inf_PaymentRules(ChargeRule,PayRule,ChargeDiffMonths,PayDiffMonths,StateDiffMonths,InJobAddRepayMonths
                ,DelayCompensationMonths,IsLocalMonthStopPay,IsNextMonthStopPay,MaxStateMonths,StateEndDay,ZoneName,ServType)
                Values ('{0}','{1}',{2},{3},{4},{5},{6},'{7}','{8}',{9},{10},'{11}','{12}')", ChargeRule, PayRule, ChargeDiffMonths.ToString(), PayDiffMonths.ToString(), StateDiffMonths.ToString()
                , InJobAddRepayMonths.ToString(), DelayCompensationMonths.ToString(), IsLocalMonthStopPay ? "1" : "0", IsNextMonthStopPay ? "1" : "0", MaxStateMonths.ToString(), StateEndDay.ToString()
                , ZoneName, ServType);
            MyDb.pub_ExecBySqlText(Sql);
        }

        private void _UpdateInfo(string ChargeRule, string PayRule, int ChargeDiffMonths, int PayDiffMonths
, int StateDiffMonths, int InJobAddRepayMonths, int DelayCompensationMonths, bool IsLocalMonthStopPay
, bool IsNextMonthStopPay, int MaxStateMonths, int StateEndDay)
        {
            string Sql = string.Format(@"Update Inf_PaymentRules
                Set ChargeRule='{0}',PayRule='{1}',ChargeDiffMonths={2},PayDiffMonths={3},StateDiffMonths={4},InJobAddRepayMonths={5},DelayCompensationMonths={6}
                ,IsLocalMonthStopPay='{7}',IsNextMonthStopPay='{8}',MaxStateMonths={9},StateEndDay={10}
                Where ZoneName='{11}' and ServType='{12}'"
                , ChargeRule, PayRule, ChargeDiffMonths.ToString(), PayDiffMonths.ToString(), StateDiffMonths.ToString()
                , InJobAddRepayMonths.ToString(), DelayCompensationMonths.ToString(), IsLocalMonthStopPay ? "1" : "0", IsNextMonthStopPay ? "1" : "0", MaxStateMonths.ToString(), StateEndDay.ToString()
                , ZoneName, ServType);
            MyDb.pub_ExecBySqlText(Sql);
        }
        /// <summary>
        /// 是否已存在该地区的相关信息
        /// </summary>
        /// <returns></returns>
        private bool IsHaveInfo()
        {
            string Sql = string.Format(@"Select COUNT(*) as Counter
                From Inf_PaymentRules Where ZoneName='{0}' and ServType='{1}'
                ", ZoneName, ServType);
            return MyDb.GetDataTable(Sql).Rows[0][0].ToString() == "0" ? false : true;
        }
        #endregion

        #region 公共方法
        /// <summary>
        /// 增加规则
        /// </summary>
        /// <returns></returns>
        public bool AddPayment(string ChargeRule, string PayRule, int ChargeDiffMonths, int PayDiffMonths
, int StateDiffMonths, int InJobAddRepayMonths, int DelayCompensationMonths, bool IsLocalMonthStopPay
, bool IsNextMonthStopPay, int MaxStateMonths, int StateEndDay)
        {
            bool finder = IsHaveInfo();
            if (!finder)
            {
                _AddInfo(ChargeRule, PayRule, ChargeDiffMonths, PayDiffMonths
                    , StateDiffMonths, InJobAddRepayMonths, DelayCompensationMonths, IsLocalMonthStopPay
                    , IsNextMonthStopPay, MaxStateMonths, StateEndDay);
            }

            return !finder;
        }
        /// <summary>
        /// 修改规则
        /// </summary>
        public void UpdatePayment(string ChargeRule, string PayRule, int ChargeDiffMonths, int PayDiffMonths
, int StateDiffMonths, int InJobAddRepayMonths, int DelayCompensationMonths, bool IsLocalMonthStopPay
, bool IsNextMonthStopPay, int MaxStateMonths, int StateEndDay)
        {
            _UpdateInfo(ChargeRule, PayRule, ChargeDiffMonths, PayDiffMonths
                , StateDiffMonths, InJobAddRepayMonths, DelayCompensationMonths, IsLocalMonthStopPay
                , IsNextMonthStopPay, MaxStateMonths, StateEndDay);
        }
        #endregion
    }
    /// <summary>
    /// PaymentRules_CorpZone
    /// </summary>
    public class PaymentRules_CorpZone
    {
        private Mydb MyDb = new Mydb();

        #region 变量
        /// <summary>
        /// 企业名
        /// </summary>
        public string CorpID;
        /// <summary>
        /// 地区名
        /// </summary>
        public string ZoneName;
        /// <summary>
        /// 服务类型
        /// </summary>
        public string ServType;
        #endregion

        #region 私有方法
        private void _AddInfoRules_CorpZone(string ID, string CorpName, string ChargeRule, string PayRule)
        {
            string Sql = string.Format(@"Insert Into Inf_PaymentRules_CorpZone(
                ID,CorpID,CorpName,ZoneName,ServType,ChargeRule,PayRule)
                Values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", ID, CorpID, CorpName, ZoneName, ServType, ChargeRule, PayRule); 
            MyDb.pub_ExecBySqlText(Sql);
        }

        private void _UpdateInfoRules_CorpZone(string ChargeRule, string PayRule)
        {
            string Sql = string.Format(@"Update Inf_PaymentRules_CorpZone
                Set ChargeRule='{0}',PayRule='{1}'
                Where CorpID='{2}' and ZoneName='{3}' and ServType='{4}'", ChargeRule, PayRule
                ,CorpID, ZoneName, ServType);
            MyDb.pub_ExecBySqlText(Sql);
        }
        /// <summary>
        /// 是否已存在该企业的相关信息
        /// </summary>
        /// <returns></returns>
        private bool IsHaveInfo_CorpZone()
        {
            string Sql = string.Format(@"Select COUNT(*) as Counter
                From Inf_PaymentRules_CorpZone Where ZoneName='{0}' and ServType='{1}' and CorpID='{2}'
                ", ZoneName, ServType, CorpID);
            return MyDb.GetDataTable(Sql).Rows[0][0].ToString() == "0" ? false : true;
        }
        #endregion

        #region 公共方法
        /// <summary>
        /// 增加规则
        /// </summary>
        /// <returns></returns>
        public bool AddPaymentRules_CorpZone(string ID, string CorpName, string ChargeRule, string PayRule)
        {
            bool finder = IsHaveInfo_CorpZone();
            if (!finder)
            {
                _AddInfoRules_CorpZone(ID, CorpName, ChargeRule, PayRule);
            }

            return !finder;
        }
        /// <summary>
        /// 修改规则
        /// </summary>
        public void UpdatePaymentRules_CorpZone(string ChargeRule, string PayRule)
        {
            _UpdateInfoRules_CorpZone(ChargeRule, PayRule);
        }
        #endregion

    }
}
